package com.ba.utils;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;

import com.ba.objects.Musteri;

public class MusteriIslemleri {
	public Musteri getMusteriById(int id) {
		ConnectionUtil connectionUtil = new ConnectionUtil(DBConfig.DB_DRIVER,
				DBConfig.DB_CONNECTION_URL, DBConfig.DB_USERNAME,
				DBConfig.DB_PASSWORD);

		Connection connection = connectionUtil.getConnection();

		String sql = "call get_musteri_by_id2(?,?,?,?)";
		Musteri musteri = new Musteri();
		try {

			CallableStatement callableStatement = connection.prepareCall(sql);
			callableStatement.setInt(1, id);
			callableStatement.registerOutParameter(2, Types.VARCHAR);
			callableStatement.registerOutParameter(3, Types.VARCHAR);
			callableStatement.registerOutParameter(4, Types.DATE);

			callableStatement.executeUpdate();

			musteri.setAd(callableStatement.getString(2));
			musteri.setSoyad(callableStatement.getString(3));
			musteri.setDogumTarih(callableStatement.getDate(4));

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			connectionUtil.closeConnection();
		}
		return musteri;
	}
}
